package com.tich.user.listener;



import com.tich.constant.RabbitMqConstant;
import com.tich.user.domain.entity.User;
import com.tich.user.domain.entity.UserInfo;
import com.tich.user.mapper.UserInfoMapper;
import com.tich.user.mapper.UserMapper;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserDeleteListener {

    @Autowired
    UserMapper userMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;

    @RabbitListener(bindings = @QueueBinding(
            value =  @Queue(name = RabbitMqConstant.USER_DELETE_QUEUE),
            exchange = @Exchange(name = RabbitMqConstant.USER_DIRECT,type = ExchangeTypes.DIRECT),
            key = RabbitMqConstant.USER_DELETE_KEY
        )
    )
    public void deletedListener(User user) {
        userMapper.saveLogoff(user);
    }

    @RabbitListener(bindings = @QueueBinding(
            value =  @Queue(name = RabbitMqConstant.USERINFO_DELETE_QUEUE),
            exchange = @Exchange(name = RabbitMqConstant.USER_DIRECT,type = ExchangeTypes.DIRECT),
            key = RabbitMqConstant.USERINFO_DELETE_KEY
        )
    )
    public void deletedInfoListener(UserInfo userInfo) {
        userInfoMapper.saveLogoff(userInfo);
    }
}
